cmake_minimum_required(VERSION 3.10)
project(photo LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(MSVC)
  set(
    CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} /bigobj /MP /wd4005 /wd4996 /wd4819 /wd4251 /wd4267 /wd4244 /wd4275 /wd4530 /wd4334 /wd4018"
    )
  add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
  add_compile_options("/utf-8")
endif(MSVC)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  set(CMAKE_CXX_FLAGS 
    "${CMAKE_CXX_FLAGS} -Wno-write-strings -Wno-unused-result -Wno-ignored-attributes"
  )
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

option(PHOTO_PROBLEM_1 "Build problem 1" OFF)
option(PHOTO_PROBLEM_2 "Build problem 2" OFF)
option(PHOTO_PROBLEM_3 "Build problem 3" OFF)

find_package(Catch2 REQUIRED)
find_package(Eigen3 REQUIRED)

# ceres
find_package(Ceres REQUIRED)

add_subdirectory(depends)

include_directories(${EIGEN3_INCLUDE_DIR})
if(${PHOTO_PROBLEM_1})
    add_executable(problem1 problem1/main.cpp)
    target_link_libraries(problem1 Catch2::Catch2)
endif()

if(${PHOTO_PROBLEM_2})
    file(GLOB SOURCES "problem2/*.cpp")
    add_executable(problem2 ${SOURCES})
    target_link_libraries(problem2 Catch2::Catch2 ceres autodiff)
endif()

if(${PHOTO_PROBLEM_3})
    file(GLOB SOURCES "problem3/*.cpp" "problem3/*.h")
    add_executable(problem3 ${SOURCES})
    target_link_libraries(problem3 Catch2::Catch2 ceres autodiff)
endif()